* Table A7: Sensitivity of NLSY79 Mobility Estimates

clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
keep if survey==1979

*drop if miss0 | miss1
drop if (mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) 
 
 
 gen N_early = .
 tab n  if surv79==0 & women==0 & miss0==0  & miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==0 & women==0 & miss0==0  & miss1_early==0
 tab n  if surv79==0 & women==1  & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==0 & women==1 & miss0==0  & miss1_early==0
 tab n  if surv79==1 & women==0  & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==1 & women==0 & miss0==0 & miss1_early==0
 tab n  if surv79==1 & women==1 & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==1 & women==1 & miss0==0   & miss1_early==0
 
 
gen N_prime = .
 tab n  if surv79==0 & women==0 & miss0==0  & miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==0 & women==0 & miss0==0  & miss1_prime==0
 tab n  if surv79==0 & women==1  & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==0 & women==1 & miss0==0  & miss1_prime==0
 tab n  if surv79==1 & women==0  & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==1 & women==0 & miss0==0 & miss1_prime==0
 tab n  if surv79==1 & women==1 & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==1 & women==1 & miss0==0   & miss1_prime==0 
 
 
* Family Income Rank in Parent Generation (Early Income)
gen faminc0_nm_early = faminc0
replace faminc0_nm_early = . if !(miss0==0 & miss1_early==0)
set sortseed 6688571
sort women surv79 faminc0_nm_early
by women surv79: gen __rank0_early = sum(weight) if  miss0==0 & miss1_early==0
gen _rank0_early = __rank0_early/N_early if  miss0==0 & miss1_early==0
by women surv79 faminc0_nm_early: egen rank0_early = mean(_rank0_early) if  miss0==0 & miss1_early==0
 replace rank0_early = 100*rank0_early
drop faminc0_nm_early __rank0_early __rank0_early 
 
* Family Income Rank in Kid Generation (Early Income)
gen faminc1_nm_early = faminc1_early
 replace faminc1_nm_early = . if !(miss0==0 & miss1_early==0)
set sortseed 6688571
sort women surv79 faminc1_nm_early
by women surv79: gen __rank1_early = sum(weight) if  miss0==0 & miss1_early==0
gen _rank1_early = __rank1_early/N_early if  miss0==0 & miss1_early==0
bys women surv79 faminc1_nm_early: egen rank1_early = mean(_rank1_early) if  miss0==0 & miss1_early==0
replace rank1_early = 100*rank1_early


* Family Income Rank in Parent Generation (Prime Income)
gen faminc0_nm_prime = faminc0
replace faminc0_nm_prime = . if !(miss0==0 & miss1_prime==0)
set sortseed 6688571
sort women surv79 faminc0_nm_prime
by women surv79: gen __rank0_prime = sum(weight) if  miss0==0 & miss1_prime==0
gen _rank0_prime = __rank0_prime/N_prime if  miss0==0 & miss1_prime==0
by women surv79 faminc0_nm_prime: egen rank0_prime = mean(_rank0_prime) if  miss0==0 & miss1_prime==0
 replace rank0_prime = 100*rank0_prime
drop faminc0_nm_prime __rank0_prime __rank0_prime 
 
* Family Income Rank in Kid Generation (Prime Income)
gen faminc1_nm_prime = faminc1_prime
 replace faminc1_nm_prime = . if !(miss0==0 & miss1_prime==0)
set sortseed 6688571
sort women surv79 faminc1_nm_prime
by women surv79: gen __rank1_prime = sum(weight) if  miss0==0 & miss1_prime==0
gen _rank1_prime = __rank1_prime/N_prime if  miss0==0 & miss1_prime==0
bys women surv79 faminc1_nm_prime: egen rank1_prime = mean(_rank1_prime) if  miss0==0 & miss1_prime==0
replace rank1_prime = 100*rank1_prime 


* --------- Rank-Rank --------- *


* Pooled
reg rank1_prime rank0_prime women if !(miss0 | miss1_prime ) [w=weight] , cluster(hhid)
eststo rank_p_prime
gen s=e(sample)

* Women
reg rank1_prime rank0_prime if women==1 & !(miss0 | miss1_prime ) [w=weight] , cluster(hhid)
eststo rank_w_prime


* Men
reg rank1_prime rank0_prime if women==0 & !(miss0 | miss1_prime) [w=weight] , cluster(hhid)
eststo rank_m_prime


* Test equality of coefficients
reg rank1_prime rank0_prime if !(miss0 | miss1_prime ) [w=weight]
est store prime_r
reg rank1_prime rank0_prime if women==1 & !(miss0 | miss1_prime) [w=weight]
est store women_r_prime
reg rank1_prime rank0_prime if women==0 & !(miss0 | miss1_prime ) [w=weight] 
est store men_r_prime

suest women_r_prime men_r_prime, cluster(hhid)
test [women_r_prime_mean]rank0_prime = [men_r_prime_mean]rank0_prime
estadd scalar p = r(p): rank_w_prime

* --------- IGE --------- *

* Pooled
reg lfaminc1_prime lfaminc0 women if !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_p_prime


* Women
reg lfaminc1_prime lfaminc0 if women==1 & !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_w_prime


* Men
reg lfaminc1_prime lfaminc0 if women==0 & !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_m_prime


* Test equality of coefficients
reg lfaminc1_prime lfaminc0 if !(miss0 | miss1_prime ) [w=weight] 
est store prime_i
reg lfaminc1_prime lfaminc0 if women==1 & !(miss0 | miss1_prime ) [w=weight] 
est store women_i_prime
reg lfaminc1_prime lfaminc0 if women==0 & !(miss0 | miss1_prime ) [w=weight]  
est store men_i_prime

suest women_i_prime men_i_prime, cluster(hhid)
test [women_i_prime_mean]lfaminc0 = [men_i_prime_mean]lfaminc0
estadd scalar p = r(p): IGE_w_prime



#delimit ;
estout rank_p_prime IGE_p_prime rank_w_prime IGE_w_prime rank_m_prime IGE_m_prime
	using  "${results_dir}tableA7.txt", replace
	keep(rank0_prime)
	rename(lfaminc0 rank0_prime)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(N p) stardrop(*) ;	
#delimit cr	
	
	
	
	

* --------- Rank-Rank --------- *



* Pooled
reg rank1_early rank0_early women if !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo rank_p_early

* Women
reg rank1_early rank0_early if women==1 & !(miss0 | miss1_early) [w=weight] , cluster(hhid)
eststo rank_w_early

* Men
reg rank1_early rank0_early if women==0 & !(miss0 | miss1_early) [w=weight] , cluster(hhid)
eststo rank_m_early

* Test equality of coefficients
reg rank1_early rank0_early if !(miss0 | miss1_early) [w=weight]
est store early_r
reg rank1_early rank0_early if women==1 & !(miss0 | miss1_early) [w=weight]
est store women_r_early
reg rank1_early rank0_early if women==0 & !(miss0 | miss1_early)  [w=weight] 
est store men_r_early

suest women_r_early men_r_early, cluster(hhid)
test [women_r_early_mean]rank0_early = [men_r_early_mean]rank0_early
estadd scalar p = r(p): rank_w_early

suest early_r prime_r, cluster(hhid)
test [early_r_mean]rank0_early = [prime_r_mean]rank0_prime
estadd scalar p2 = r(p): rank_p_early



suest women_r_early women_r_prime, cluster(hhid)
test [women_r_early_mean]rank0_early = [women_r_prime_mean]rank0_prime
estadd scalar p2 = r(p): rank_w_early

suest men_r_early men_r_prime, cluster(hhid)
test [men_r_early_mean]rank0_early = [men_r_prime_mean]rank0_prime
estadd scalar p2 = r(p): rank_m_early

* --------- IGE --------- *

* Pooled
reg lfaminc1_early lfaminc0 women if !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_p_early



* Women
reg lfaminc1_early lfaminc0 if women==1 & !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_w_early


* Men
reg lfaminc1_early lfaminc0 if women==0 & !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_m_early
	
* Test equality of coefficients
reg lfaminc1_early lfaminc0 if !(miss0 | miss1_early) [w=weight]
est store early_i
reg lfaminc1_early lfaminc0 if women==1 & !(miss0 | miss1_early) [w=weight]
est store women_i_early
reg lfaminc1_early lfaminc0 if women==0 & !(miss0 | miss1_early) [w=weight] 
est store men_i_early

suest women_i_early men_i_early, cluster(hhid)
test [women_i_early_mean]lfaminc0 = [men_i_early_mean]lfaminc0
estadd scalar p = r(p): IGE_w_early	

suest early_i prime_i, cluster(hhid)
test [early_i_mean]lfaminc0 = [prime_i_mean]lfaminc0
estadd scalar p2 = r(p): IGE_p_early



suest women_i_early women_i_prime, cluster(hhid)
test [women_i_early_mean]lfaminc0 = [women_i_prime_mean]lfaminc0
estadd scalar p2 = r(p): IGE_w_early

suest men_i_early men_i_prime, cluster(hhid)
test [men_i_early_mean]lfaminc0 = [men_i_prime_mean]lfaminc0
estadd scalar p2 = r(p): IGE_m_early

	

#delimit ;
estout rank_p_early IGE_p_early rank_w_early IGE_w_early rank_m_early IGE_m_early
	using  "${results_dir}tableA7.txt", append
	keep(rank0_early)
	rename(lfaminc0 rank0_early)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(N p p2) stardrop(*) ;	
#delimit cr	
		
		
		
		

		
clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
keep if survey==1979



 gen N_early = .
 tab n  if surv79==0 & women==0 & miss0==0  & miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==0 & women==0 & miss0==0  & miss1_early==0
 tab n  if surv79==0 & women==1  & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==0 & women==1 & miss0==0  & miss1_early==0
 tab n  if surv79==1 & women==0  & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==1 & women==0 & miss0==0 & miss1_early==0
 tab n  if surv79==1 & women==1 & miss0==0 &  miss1_early==0 [w=weight]
 replace N_early = r(N) if surv79==1 & women==1 & miss0==0   & miss1_early==0
 
 
gen N_prime = .
 tab n  if surv79==0 & women==0 & miss0==0  & miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==0 & women==0 & miss0==0  & miss1_prime==0
 tab n  if surv79==0 & women==1  & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==0 & women==1 & miss0==0  & miss1_prime==0
 tab n  if surv79==1 & women==0  & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==1 & women==0 & miss0==0 & miss1_prime==0
 tab n  if surv79==1 & women==1 & miss0==0 &  miss1_prime==0 [w=weight]
 replace N_prime = r(N) if surv79==1 & women==1 & miss0==0   & miss1_prime==0 
 
 
* Family Income Rank in Parent Generation (Early Income)
gen faminc0_nm_early = faminc0
replace faminc0_nm_early = . if !(miss0==0 & miss1_early==0)
set sortseed 6688571
sort women surv79 faminc0_nm_early
by women surv79: gen __rank0_early = sum(weight) if  miss0==0 & miss1_early==0
gen _rank0_early = __rank0_early/N_early if  miss0==0 & miss1_early==0
by women surv79 faminc0_nm_early: egen rank0_early = mean(_rank0_early) if  miss0==0 & miss1_early==0
 replace rank0_early = 100*rank0_early
drop faminc0_nm_early __rank0_early __rank0_early 
 
* Family Income Rank in Kid Generation (Early Income)
gen faminc1_nm_early = faminc1_early
 replace faminc1_nm_early = . if !(miss0==0 & miss1_early==0)
set sortseed 6688571
sort women surv79 faminc1_nm_early
by women surv79: gen __rank1_early = sum(weight) if  miss0==0 & miss1_early==0
gen _rank1_early = __rank1_early/N_early if  miss0==0 & miss1_early==0
bys women surv79 faminc1_nm_early: egen rank1_early = mean(_rank1_early) if  miss0==0 & miss1_early==0
replace rank1_early = 100*rank1_early


* Family Income Rank in Parent Generation (Prime Income)
gen faminc0_nm_prime = faminc0
replace faminc0_nm_prime = . if !(miss0==0 & miss1_prime==0)
set sortseed 6688571
sort women surv79 faminc0_nm_prime
by women surv79: gen __rank0_prime = sum(weight) if  miss0==0 & miss1_prime==0
gen _rank0_prime = __rank0_prime/N_prime if  miss0==0 & miss1_prime==0
by women surv79 faminc0_nm_prime: egen rank0_prime = mean(_rank0_prime) if  miss0==0 & miss1_prime==0
 replace rank0_prime = 100*rank0_prime
drop faminc0_nm_prime __rank0_prime __rank0_prime 
 
* Family Income Rank in Kid Generation (Prime Income)
gen faminc1_nm_prime = faminc1_prime
 replace faminc1_nm_prime = . if !(miss0==0 & miss1_prime==0)
set sortseed 6688571
sort women surv79 faminc1_nm_prime
by women surv79: gen __rank1_prime = sum(weight) if  miss0==0 & miss1_prime==0
gen _rank1_prime = __rank1_prime/N_prime if  miss0==0 & miss1_prime==0
bys women surv79 faminc1_nm_prime: egen rank1_prime = mean(_rank1_prime) if  miss0==0 & miss1_prime==0
replace rank1_prime = 100*rank1_prime 


* --------- Rank-Rank --------- *

* Pooled
* Pooled
reg rank1_prime rank0_prime women if !(miss0 | miss1_prime ) [w=weight] , cluster(hhid)
eststo rank_p_prime
gen s=e(sample)

* Women
reg rank1_prime rank0_prime if women==1 & !(miss0 | miss1_prime ) [w=weight] , cluster(hhid)
eststo rank_w_prime


* Men
reg rank1_prime rank0_prime if women==0 & !(miss0 | miss1_prime) [w=weight] , cluster(hhid)
eststo rank_m_prime


* Test equality of coefficients
reg rank1_prime rank0_prime if !(miss0 | miss1_prime ) [w=weight]
est store prime_r
reg rank1_prime rank0_prime if women==1 & !(miss0 | miss1_prime) [w=weight]
est store women_r_prime
reg rank1_prime rank0_prime if women==0 & !(miss0 | miss1_prime ) [w=weight] 
est store men_r_prime

suest women_r_prime men_r_prime, cluster(hhid)
test [women_r_prime_mean]rank0_prime = [men_r_prime_mean]rank0_prime
estadd scalar p = r(p): rank_w_prime

* --------- IGE --------- *

* Pooled
reg lfaminc1_prime lfaminc0 women if !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_p_prime


* Women
reg lfaminc1_prime lfaminc0 if women==1 & !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_w_prime


* Men
reg lfaminc1_prime lfaminc0 if women==0 & !(miss0 | miss1_prime ) [w=weight], cluster(hhid)
eststo IGE_m_prime


* Test equality of coefficients
reg lfaminc1_prime lfaminc0 if !(miss0 | miss1_prime ) [w=weight] 
est store prime_i
reg lfaminc1_prime lfaminc0 if women==1 & !(miss0 | miss1_prime ) [w=weight] 
est store women_i_prime
reg lfaminc1_prime lfaminc0 if women==0 & !(miss0 | miss1_prime ) [w=weight]  
est store men_i_prime

suest women_i_prime men_i_prime, cluster(hhid)
test [women_i_prime_mean]lfaminc0 = [men_i_prime_mean]lfaminc0
estadd scalar p = r(p): IGE_w_prime



#delimit ;
estout rank_p_prime IGE_p_prime rank_w_prime IGE_w_prime rank_m_prime IGE_m_prime
	using  "${results_dir}tableA7.txt", append
	keep(rank0_prime)
	rename(lfaminc0 rank0_prime)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(N p) stardrop(*) ;	
#delimit cr	
	
	
	

* --------- Rank-Rank --------- *

* Pooled
reg rank1_early rank0_early women if !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo rank_p_early

* Women
reg rank1_early rank0_early if women==1 & !(miss0 | miss1_early) [w=weight] , cluster(hhid)
eststo rank_w_early

* Men
reg rank1_early rank0_early if women==0 & !(miss0 | miss1_early) [w=weight] , cluster(hhid)
eststo rank_m_early

* Test equality of coefficients
reg rank1_early rank0_early if !(miss0 | miss1_early) [w=weight]
est store early_r
reg rank1_early rank0_early if women==1 & !(miss0 | miss1_early) [w=weight]
est store women_r_early
reg rank1_early rank0_early if women==0 & !(miss0 | miss1_early)  [w=weight] 
est store men_r_early

suest women_r_early men_r_early, cluster(hhid)
test [women_r_early_mean]rank0_early = [men_r_early_mean]rank0_early
estadd scalar p = r(p): rank_w_early

suest early_r prime_r, cluster(hhid)
test [early_r_mean]rank0_early = [prime_r_mean]rank0_prime
estadd scalar p2 = r(p): rank_p_early



suest women_r_early women_r_prime, cluster(hhid)
test [women_r_early_mean]rank0_early = [women_r_prime_mean]rank0_prime
estadd scalar p2 = r(p): rank_w_early

suest men_r_early men_r_prime, cluster(hhid)
test [men_r_early_mean]rank0_early = [men_r_prime_mean]rank0_prime
estadd scalar p2 = r(p): rank_m_early

* --------- IGE --------- *

* Pooled
reg lfaminc1_early lfaminc0 women if !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_p_early



* Women
reg lfaminc1_early lfaminc0 if women==1 & !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_w_early


* Men
reg lfaminc1_early lfaminc0 if women==0 & !(miss0 | miss1_early) [w=weight], cluster(hhid)
eststo IGE_m_early
	
* Test equality of coefficients
reg lfaminc1_early lfaminc0 if !(miss0 | miss1_early) [w=weight]
est store early_i
reg lfaminc1_early lfaminc0 if women==1 & !(miss0 | miss1_early) [w=weight]
est store women_i_early
reg lfaminc1_early lfaminc0 if women==0 & !(miss0 | miss1_early) [w=weight] 
est store men_i_early

suest women_i_early men_i_early, cluster(hhid)
test [women_i_early_mean]lfaminc0 = [men_i_early_mean]lfaminc0
estadd scalar p = r(p): IGE_w_early	

suest early_i prime_i, cluster(hhid)
test [early_i_mean]lfaminc0 = [prime_i_mean]lfaminc0
estadd scalar p2 = r(p): IGE_p_early



suest women_i_early women_i_prime, cluster(hhid)
test [women_i_early_mean]lfaminc0 = [women_i_prime_mean]lfaminc0
estadd scalar p2 = r(p): IGE_w_early

suest men_i_early men_i_prime, cluster(hhid)
test [men_i_early_mean]lfaminc0 = [men_i_prime_mean]lfaminc0
estadd scalar p2 = r(p): IGE_m_early

	

#delimit ;
estout rank_p_early IGE_p_early rank_w_early IGE_w_early rank_m_early IGE_m_early
	using  "${results_dir}tableA7.txt", append
	keep(rank0_early)
	rename(lfaminc0 rank0_early)
	cells(b(star fmt(3))  se(par fmt(3))) 
	collabels(,none) stat(N p p2) stardrop(*) ;	
#delimit cr	
		
		
		
		